﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x020001CF RID: 463
public class ResizeManager : MonoBehaviour
{
	// Token: 0x060009EC RID: 2540 RVA: 0x00059499 File Offset: 0x00057699
	public void AddResizer(ResizeManager.Resizer resizer)
	{
		resizer.Init(base.GetComponent<EntityBase>());
		if (resizer.loop)
		{
			this.loopResizer = resizer;
		}
		else
		{
			this.resizers.Add(resizer);
		}
	}

	// Token: 0x060009ED RID: 2541 RVA: 0x000594CC File Offset: 0x000576CC
	private void Update()
	{
		this.loopResizer.Update();
		for (int i = this.resizers.Count - 1; i >= 0; i--)
		{
			if (this.resizers[i].Update())
			{
				this.resizers.RemoveAt(i);
			}
		}
	}

	// Token: 0x04000F6D RID: 3949
	private ResizeManager.Resizer loopResizer = new ResizeManager.Resizer(1f, 0f, true);

	// Token: 0x04000F6E RID: 3950
	private List<ResizeManager.Resizer> resizers = new List<ResizeManager.Resizer>();

	// Token: 0x020001D0 RID: 464
	public class Resizer
	{
		// Token: 0x060009EE RID: 2542 RVA: 0x00059525 File Offset: 0x00057725
		public Resizer(float duration, float factor, bool loop)
		{
			this.duration = duration;
			this.factor = factor;
			this.loop = loop;
		}

		// Token: 0x060009EF RID: 2543 RVA: 0x00059544 File Offset: 0x00057744
		public void Init(EntityBase entity)
		{
			this.entity = entity;
			this.startTime = Time.time;
			this.originalScale = entity.transform.localScale.y;
		}

		// Token: 0x060009F0 RID: 2544 RVA: 0x0005957C File Offset: 0x0005777C
		public bool Update()
		{
			if (this.factor == 0f)
			{
				return true;
			}
			float y = this.entity.transform.localScale.y;
			float num;
			if (this.duration == 0f)
			{
				num = 1f;
			}
			else
			{
				float b = this.startTime + this.duration - Time.time + Time.smoothDeltaTime;
				num = Mathf.Min(Time.smoothDeltaTime, b) / this.duration;
			}
			float num2 = this.originalScale * this.factor * num;
			float num3 = y + num2;
			this.entity.ChangeScale(num3);
			if (num3 > this.entity.maxSize || num3 < this.entity.minSize)
			{
				this.factor = 0f;
			}
			if (Time.time >= this.startTime + this.duration)
			{
				if (this.loop)
				{
					this.startTime += this.duration;
					this.originalScale = num3;
				}
				else
				{
					this.factor = 0f;
				}
			}
			return false;
		}

		// Token: 0x060009F1 RID: 2545 RVA: 0x0005969D File Offset: 0x0005789D
		public bool IsCompleted()
		{
			return this.loop || this.factor == 0f;
		}

		// Token: 0x060009F2 RID: 2546 RVA: 0x000596BA File Offset: 0x000578BA
		public void Interrupt()
		{
			if (!this.loop)
			{
				this.factor = 0f;
			}
		}

		// Token: 0x04000F6F RID: 3951
		private EntityBase entity;

		// Token: 0x04000F70 RID: 3952
		private float startTime;

		// Token: 0x04000F71 RID: 3953
		private float duration;

		// Token: 0x04000F72 RID: 3954
		private float factor;

		// Token: 0x04000F73 RID: 3955
		public readonly bool loop;

		// Token: 0x04000F74 RID: 3956
		private float originalScale;
	}
}
